package com.zhoux.others;

import java.util.Random;

/**
 * @author taoyi
 * @version 1.0
 * @date 2021/3/12 14:14
 */
public class Ak47 {
    private int bullet = 100;


    // 模拟开枪功能
    public void fire(){
        if (this.bullet==0){ // 判断枪里是否有子弹，没有子弹无法开枪
            System.out.println("没有子弹啦！");
            return;
        }
        // 1.生成一个随机数来表示打出的子弹数量
        Random random = new Random();
        int bullets = random.nextInt(20);
        if (bullets > bullet){
            for (int i = 0; i < bullet; i++) {
                System.out.print("突~");
            }
            System.out.println();
            bullet = 0;
            System.out.println("子弹打完啦~~~~");
        }else {
            bullet -= bullets;
            for (int i = 0; i < bullets; i++) {
                System.out.print("突~");
            }
            System.out.println();
        }
    }

    // 模拟填充子弹
    public void load(){
        this.bullet = 100;
        System.out.println("子弹装好啦~");
    }


    public Ak47() {
    }

    public Ak47(int bullet) {
        this.bullet = bullet;
    }

    public int getBullet() {
        return bullet;
    }

    public void setBullet(int bullet) {
        this.bullet = bullet;
    }
}
